package com.example.administrator.dc.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.dc.Bean.DataEntity;
import com.example.administrator.dc.Bean.Dataphoto;
import com.example.administrator.dc.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/8/25.
 */

public class Photolistadapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<Dataphoto> collectlist;
    public Photolistadapter(Context cxt,List<Dataphoto> photolsit){
        this.context =cxt;
        this.collectlist=photolsit;
        layoutInflater=layoutInflater.from(cxt);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.photo_list,parent,false);
        Photolistadapter.ViewHolder viewHolder=new Photolistadapter.ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof Photolistadapter.ViewHolder) {
            final Photolistadapter.ViewHolder viewHolder = (Photolistadapter.ViewHolder) holder;
            final Dataphoto cook = collectlist.get(position);
            viewHolder.user_info.setText(cook.getTitle());
            viewHolder.user_read.setText(cook.getCreatetime());
            if (!"".equals(cook.getPhoto()))
                Picasso.with(context).load(cook.getPhoto()).into(viewHolder.user_image);
            if(!"1".equals(cook.getGender()+"")){
                viewHolder.user_bottom.setBackgroundResource(R.color.myhome_top_text_color);
                viewHolder.user_info.setTextColor(viewHolder.user_info.getResources().getColor(R.color.myhome_top_text_color));}
            else
            {viewHolder.user_bottom.setBackgroundResource(R.color.pink);
                viewHolder.user_info.setTextColor(viewHolder.user_info.getResources().getColor(R.color.pink));}


        }

    }
    @Override
    public int getItemCount() {
        return collectlist==null ? 0:collectlist.size();
    }



    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView user_info;
        ImageView user_image;
        TextView user_read;
        TextView user_collect;
        ImageView imageView_collect1;
        RelativeLayout user_bottom;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView_collect1= (ImageView) itemView.findViewById(R.id.imageView_collect);
            user_info = (TextView) itemView.findViewById(R.id.cardview_myhome_info);
            user_image = (ImageView) itemView.findViewById(R.id.cardview_myhome_img);
            user_read = (TextView) itemView.findViewById(R.id.num_myhome_read);
            user_collect= (TextView) itemView.findViewById(R.id.num_myhome_collect);
            user_bottom=(RelativeLayout)itemView.findViewById(R.id.cardview_bottom);

        }
    }
}
